Challenge Summary
Your organization wants to know which companies are similar to each other to help in identifying potential customers of a SAAS software solution (e.g. Salesforce CRM or equivalent) in various segments of the market. The Sales Department is very interested in this analysis, which will help them more easily penetrate various market segments.
You will be using stock prices in this analysis. You come up with a method to classify companies based on how their stocks trade using their daily stock returns (percentage movement from one day to the next). This analysis will help your organization determine which companies are related to each other (competitors and have similar attributes).
You can analyze the stock prices using what you’ve learned in the unsupervised learning tools including K-Means and UMAP. You will use a combination of kmeans() to find groups and umap() to visualize similarity of daily stock returns.
Objectives
Apply your knowledge on K-Means and UMAP along with dplyr, ggplot2, and purrr to create a visualization that identifies subgroups in the S&P 500 Index. You will specifically apply:
Modeling: kmeans() and umap()
Iteration: purrr
Data Manipulation: dplyr, tidyr, and tibble
Visualization: ggplot2 (bonus plotly)
Libraries
Load the following libraries.
library (tidyverse)
library (tidyquant)
#> Loading required package: PerformanceAnalytics
#> Loading required package: xts
#> Loading required package: zoo
#>
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#>
#> as.Date, as.Date.numeric
#>
#> ######################### Warning from 'xts' package ##########################
#> # #
#> # The dplyr lag() function breaks how base R's lag() function is supposed to #
#> # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
#> # source() into this session won't work correctly. #
#> # #
#> # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
#> # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
#> # dplyr from breaking base R's lag() function. #
#> # #
#> # Code in packages is not affected. It's protected by R's namespace mechanism #
#> # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
#> # #
#> ###############################################################################
#>
#> Attaching package: 'xts'
#> The following objects are masked from 'package:dplyr':
#>
#> first, last
#>
#> Attaching package: 'PerformanceAnalytics'
#> The following object is masked from 'package:graphics':
#>
#> legend
#> Loading required package: quantmod
#> Loading required package: TTR
#> Registered S3 method overwritten by 'quantmod':
#> method from
#> as.zoo.data.frame zoo
library (broom)
library (umap)
Data
We will be using stock prices in this analysis. Although some of you know already how to use an API to retrieve stock prices I obtained the stock prices for every stock in the S&P 500 index for you already. The files are saved in the session_6_data directory.
We can read in the stock prices. The data is 1.2M observations. The most important columns for our analysis are:
symbol: The stock ticker symbol that corresponds to a company’s stock price
date: The timestamp relating the symbol to the share price at that point in time
adjusted: The stock price, adjusted for any splits and dividends (we use this when analyzing stock data over long periods of time)
# STOCK PRICES
sp_500_prices_tbl <- read_rds ("data/01_data/sp_500_prices_tbl.rds" )
sp_500_prices_tbl
The second data frame contains information about the stocks the most important of which are:
company: The company name
sector: The sector that the company belongs to
# SECTOR INFORMATION
sp_500_index_tbl <- read_rds ("data/01_data/sp_500_index_tbl.rds" )
sp_500_index_tbl
Question
Which stock prices behave similarly?
Answering this question helps us understand which companies are related , and we can use clustering to help us answer it!
Even if you’re not interested in finance, this is still a great analysis because it will tell you which companies are competitors and which are likely in the same space (often called sectors) and can be categorized together. Bottom line - This analysis can help you better understand the dynamics of the market and competition, which is useful for all types of analyses from finance to sales to marketing.
Let’s get started.
Step 4 - Find the optimal value of K
Now that we are familiar with the process for calculating kmeans() , let’s use purrr to iterate over many values of “k” using the centers argument.
We’ll use this custom function called kmeans_mapper():
kmeans_mapper <- function (center = 3 ) {
stock_date_matrix_tbl %>%
select (- symbol) %>%
kmeans (centers = center, nstart = 20 )
}
Apply the kmeans_mapper() and glance() functions iteratively using purrr.
Create a tibble containing column called centers that go from 1 to 30
Add a column named k_means with the kmeans_mapper() output. Use mutate() to add the column and map() to map centers to the kmeans_mapper() function.
Add a column named glance with the glance() output. Use mutate() and map() again to iterate over the column of k_means.
Save the output as k_means_mapped_tbl
# Use purrr to map
k_means_mapped_tbl <- tibble (centers = 1 : 30 ) %>%
# Add k_means column to map the centers to kmeans_mapper
mutate (k_means = centers %>% map (kmeans_mapper)) %>%
# Add glance
mutate (glance = k_means %>% map (glance))
k_means_mapped_tbl
# Output: k_means_mapped_tbl
Next, let’s visualize the “tot.withinss” from the glance output as a Scree Plot .
Begin with the k_means_mapped_tbl
Unnest the glance column
Plot the centers column (x-axis) versus the tot.withinss column (y-axis) using geom_point() and geom_line()
Add a title “Scree Plot” and feel free to style it with your favorite theme
# Visualize Scree Plot
k_means_mapped_tbl %>%
unnest (glance) %>%
select (centers, tot.withinss) %>%
# Visualization
ggplot (aes (centers, tot.withinss)) +
geom_point (color = "#2DC6D6" , size = 4 ) +
geom_line (color = "#2DC6D6" , size = 1 ) +
# Add labels (which are repelled a little)
ggrepel:: geom_label_repel (aes (label = centers), color = "#2DC6D6" ) +
# Formatting
labs (title = "Skree Plot" ,
subtitle = "" ,
caption = "" )
#> Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
#> ℹ Please use `linewidth` instead.
We can see that the Scree Plot becomes linear (constant rate of change) between 5 and 10 centers for K.
Step 5 - Apply UMAP
Next, let’s plot the UMAP 2D visualization to help us investigate cluster assignments.
We’re going to import the correct results first (just in case you were not able to complete the last step).
k_means_mapped_tbl <- read_rds ("data/01_data/k_means_mapped_tbl.rds" )
First, let’s apply the umap() function to the stock_date_matrix_tbl, which contains our user-item matrix in tibble format.
Start with stock_date_matrix_tbl
De-select the symbol column
Use the umap() function storing the output as umap_results
# Apply UMAP
umap_results <- stock_date_matrix_tbl %>%
# De-select the symbol column
select (- symbol) %>%
umap ()
umap_results
#> umap embedding of 502 items in 2 dimensions
#> object components: layout, data, knn, config
# Store results as: umap_results
Next, we want to combine the layout from the umap_results with the symbol column from the stock_date_matrix_tbl.
Start with umap_results$layout
Convert from a matrix data type to a tibble with as_tibble()
Bind the columns of the umap tibble with the symbol column from the stock_date_matrix_tbl.
Save the results as umap_results_tbl.
# Convert umap results to tibble with symbols
# Start with `umap_results$layout`
umap_results_tbl <- umap_results$ layout %>%
# Convert from a `matrix` data type to a `tibble` with `as_tibble()`
as_tibble (.name_repair = "unique" ) %>% # argument is required to set names in the next step
set_names (c ("x" , "y" )) %>%
# Bind the columns of the umap tibble with the `symbol` column from the `stock_date_matrix_tbl`
bind_cols (stock_date_matrix_tbl %>% select (symbol))
#> New names:
#> • `` -> `...1`
#> • `` -> `...2`
# Output: umap_results_tbl
Finally, let’s make a quick visualization of the umap_results_tbl.
Pipe the umap_results_tbl into ggplot() mapping the columns to x-axis and y-axis
Add a geom_point() geometry with an alpha = 0.5
Apply theme_tq() and add a title “UMAP Projection”
# Visualize UMAP results
umap_results_tbl %>%
ggplot (aes (x, y)) +
geom_point (alpha = 0.5 ) +
theme_tq (base_size = 11 , base_family = "" ) +
# Formatting
labs (title = "UMAP Projection" ,
subtitle = "" ,
caption = "" )
We can now see that we have some clusters. However, we still need to combine the K-Means clusters and the UMAP 2D representation.
Step 6 - Combine K-Means and UMAP
Next, we combine the K-Means clusters and the UMAP 2D representation
We’re going to import the correct results first (just in case you were not able to complete the last step).
k_means_mapped_tbl <- read_rds ("data/01_data/k_means_mapped_tbl.rds" )
umap_results_tbl <- read_rds ("data/01_data/umap_results_tbl.rds" )
First, pull out the K-Means for 10 Centers. Use this since beyond this value the Scree Plot flattens. Have a look at the business case to recall how that works.
# Get the k_means_obj from the 10th center
kmeans_10_obj <- k_means_mapped_tbl %>%
pull (k_means) %>%
pluck (10 )
kmeans_10_obj
#> K-means clustering with 10 clusters of sizes 29, 94, 1, 73, 43, 4, 126, 46, 58, 28
#>
#> Cluster means:
#> 2018-01-03 2018-01-04 2018-01-05 2018-01-08 2018-01-09
#> 1 0.0145437485 0.011631004 0.0005726774 5.789677e-03 -0.006332892
#> 2 0.0065642160 0.006738043 0.0059085037 2.974155e-03 0.001274760
#> 3 0.0036426538 0.008295869 -0.0099417552 -6.232618e-03 0.185191579
#> 4 -0.0041425774 -0.008439491 0.0006217945 5.537889e-03 -0.009736488
#> 5 -0.0017493406 -0.001231831 0.0047699592 -8.345719e-05 0.001499131
#> 6 0.0196614543 0.009614592 0.0083596086 -5.317769e-03 -0.021632842
#> 7 0.0075626729 0.004996486 0.0082570988 2.317536e-03 0.003389852
#> 8 0.0050761435 0.008697071 0.0041779930 3.826302e-04 0.011147386
#> 9 0.0154637264 0.004805504 0.0101239450 1.033477e-02 -0.001709654
#> 10 -0.0007381898 -0.003919336 0.0073316224 2.273495e-04 -0.001901621
#> 2018-01-10 2018-01-11 2018-01-12 2018-01-16 2018-01-17
#> 1 0.001130067 0.023196792 0.010086447 -0.015274874 0.009126537
#> 2 -0.003242479 0.018020616 0.007094835 -0.009952770 0.005195221
#> 3 0.012788520 0.014223439 0.030337766 -0.031388917 -0.004875194
#> 4 -0.013601948 -0.005543798 -0.006214341 0.001676481 0.007333950
#> 5 0.001741024 0.012702317 0.009891142 -0.004211081 0.002933372
#> 6 -0.006726449 0.004202749 -0.002665092 -0.058360697 0.002897018
#> 7 -0.003891251 0.005139493 0.006378343 -0.003863188 0.009419685
#> 8 0.010289687 0.008619943 0.007922556 -0.009471434 0.008060192
#> 9 -0.002485020 0.008047997 0.010321299 -0.005522328 0.017315690
#> 10 0.004877772 0.017508752 0.016356885 -0.013608894 0.013597514
#> 2018-01-18 2018-01-19 2018-01-22 2018-01-23 2018-01-24
#> 1 -0.0105740416 0.001157641 0.025135535 -0.0007110677 -0.0064518342
#> 2 -0.0024848393 0.005794388 0.002834018 -0.0003162568 -0.0011087779
#> 3 0.0109510371 0.020381869 0.072496205 0.0131544935 -0.0161974802
#> 4 -0.0067159634 0.003412544 0.007521111 0.0088803250 -0.0049853116
#> 5 -0.0003027514 0.002334629 0.012645723 -0.0013341706 0.0049397478
#> 6 -0.0099325229 0.040441835 0.017956822 0.0379076882 -0.0122245462
#> 7 -0.0013277692 0.007329845 0.002938302 0.0026241276 0.0054174006
#> 8 -0.0054462166 0.012582562 0.006860615 0.0013132145 0.0037624435
#> 9 0.0026094959 0.004086150 0.007754607 0.0084308409 -0.0089395855
#> 10 0.0068662854 0.020098382 0.004107398 0.0011842085 -0.0006335636
#> 2018-01-25 2018-01-26 2018-01-29 2018-01-30 2018-01-31
#> 1 -0.0106173787 6.101720e-03 -0.015787016 -0.0213550985 0.001603751
#> 2 -0.0059748769 1.015495e-02 -0.009534035 -0.0096672600 -0.001700188
#> 3 0.0313602644 1.266933e-03 0.042515501 0.0007282195 0.014069182
#> 4 0.0073453686 -2.703617e-05 -0.011576359 -0.0022192040 0.012161502
#> 5 0.0003778577 1.094782e-02 -0.004185305 -0.0121631915 -0.008028483
#> 6 -0.0222533499 -1.315427e-03 -0.016453175 -0.0129734439 -0.010484817
#> 7 0.0064845613 1.146105e-02 -0.007108523 -0.0089311642 -0.001548083
#> 8 -0.0056489993 1.000797e-02 -0.004895856 -0.0175196151 -0.002431135
#> 9 -0.0042205392 2.067828e-02 -0.002746892 -0.0112683178 0.006598105
#> 10 -0.0029840426 1.062332e-02 -0.001387342 -0.0167714417 -0.012082577
#> 2018-02-01 2018-02-02 2018-02-05 2018-02-06 2018-02-07
#> 1 0.0093211650 -0.037766377 -0.03690706 0.013244579 -0.0196711210
#> 2 -0.0037978447 -0.023060851 -0.04013647 0.018172827 0.0009898671
#> 3 0.0613562605 -0.008338945 -0.06318180 -0.045002413 -0.0274355762
#> 4 -0.0166136472 -0.012720241 -0.02432818 -0.002116927 -0.0051285970
#> 5 -0.0022117398 -0.020399220 -0.03947534 0.013863817 -0.0026366719
#> 6 -0.0190634365 -0.002076577 -0.03945030 0.018994374 0.0080707901
#> 7 0.0017958753 -0.014860421 -0.03690204 0.008060500 0.0016302764
#> 8 0.0107897836 -0.021591070 -0.04651543 0.015681255 0.0004776815
#> 9 0.0008162164 -0.024417924 -0.03933827 0.027975062 -0.0106557091
#> 10 -0.0087468676 -0.023724738 -0.03206853 0.026178339 0.0012778349
#> 2018-02-08 2018-02-09 2018-02-12 2018-02-13 2018-02-14
#> 1 -0.03986800 -0.0028315968 0.022470773 -0.0059466066 0.028741740
#> 2 -0.03912016 0.0075367855 0.018609941 -0.0010055366 0.013540809
#> 3 -0.02507507 -0.0001339987 0.054394401 -0.0386276127 0.110229918
#> 4 -0.01876326 0.0213057564 0.003930112 0.0044494737 -0.005984465
#> 5 -0.02824215 0.0059781838 0.009481471 0.0022354448 0.012950118
#> 6 0.01438555 0.0408664979 0.031525687 0.0707301121 0.040448433
#> 7 -0.03467253 0.0136490167 0.010629635 0.0045887267 0.015122358
#> 8 -0.04743803 0.0192589939 0.013614735 0.0008103593 0.028478620
#> 9 -0.04103868 0.0218574145 0.018835130 0.0049581980 0.023289477
#> 10 -0.03707387 0.0137519768 -0.001253348 0.0060199275 0.025309434
#> 2018-02-15 2018-02-16 2018-02-20 2018-02-21 2018-02-22
#> 1 -0.005527208 -0.0051308189 0.0001945716 -0.0169459770 0.009698184
#> 2 0.008110574 -0.0005391426 -0.0059456862 -0.0016953714 0.003347874
#> 3 -0.022142869 0.0157049064 0.0002396860 0.0359496718 0.020358613
#> 4 0.017038758 0.0059424591 -0.0117238557 -0.0177334881 0.008159557
#> 5 0.011237394 0.0023648945 -0.0126842856 -0.0095531145 -0.003510870
#> 6 0.025453792 -0.0327184475 -0.0132688464 0.0006828019 -0.018994639
#> 7 0.012223535 0.0025440218 -0.0074921851 -0.0032985602 -0.001808385
#> 8 0.001903319 0.0029184710 -0.0020222832 0.0026789595 -0.013078914
#> 9 0.017024057 -0.0060666804 0.0084390366 -0.0067996418 -0.002970803
#> 10 0.008745195 -0.0068438891 -0.0143390752 0.0029664385 0.005293028
#> 2018-02-23 2018-02-26 2018-02-27 2018-02-28 2018-03-01
#> 1 0.02186558 -0.0001523236 -0.014192763 -0.024117444 0.0018311893
#> 2 0.01079368 0.0085391020 -0.015577972 -0.015291194 -0.0129581588
#> 3 0.01575784 0.0107142860 -0.005631570 -0.038756301 -0.0232208300
#> 4 0.01800265 0.0019481749 -0.017312381 -0.004604333 -0.0006035957
#> 5 0.01531811 0.0096761067 -0.016220496 -0.018772323 -0.0099838154
#> 6 0.01273791 -0.0045193885 -0.022410596 -0.010970884 -0.0220073109
#> 7 0.01423814 0.0083471619 -0.009934123 -0.008745837 -0.0138927158
#> 8 0.01601208 0.0108017773 -0.010516015 -0.013439415 -0.0156374403
#> 9 0.02303929 0.0144215633 -0.008194996 -0.004895418 -0.0142134580
#> 10 0.01446056 0.0021400959 -0.019078129 0.001355020 -0.0083934481
#> 2018-03-02 2018-03-05 2018-03-06 2018-03-07 2018-03-08
#> 1 0.0075032777 0.011184483 8.554807e-05 -0.0075082198 0.0015585011
#> 2 -0.0004789283 0.010920220 9.140912e-03 -0.0019756670 0.0039724745
#> 3 0.2166765151 -0.007679605 -3.908705e-02 0.0327251211 0.0704836998
#> 4 0.0001678387 0.014350013 -3.402989e-03 -0.0012632247 0.0066435197
#> 5 0.0148490034 0.008137398 2.581041e-03 -0.0050556772 0.0054613384
#> 6 0.0449641008 0.007615378 4.742766e-03 -0.0145753490 -0.0052765302
#> 7 0.0071400867 0.010964616 4.895555e-03 0.0043559616 0.0030516198
#> 8 0.0052386317 0.013347723 8.904611e-03 0.0002367185 0.0004781494
#> 9 0.0183294948 0.014701953 9.132188e-03 0.0089743251 0.0066681599
#> 10 0.0042628566 0.004851129 5.995494e-03 -0.0227305573 -0.0120761984
#> 2018-03-09 2018-03-12 2018-03-13 2018-03-14 2018-03-15
#> 1 0.0212305234 -0.0004160591 -0.0082164133 -0.001626219 -0.0126071311
#> 2 0.0215717736 -0.0049164968 -0.0027043300 -0.010738006 -0.0018786067
#> 3 -0.0009222243 -0.0486431253 0.0008732318 0.013086448 -0.0239211554
#> 4 0.0041083850 0.0036975439 0.0013347335 0.002128121 -0.0031399519
#> 5 0.0090941626 0.0037892843 -0.0060379286 -0.005629742 -0.0078040522
#> 6 -0.0200553581 0.0027151220 -0.0283910751 -0.024853761 -0.0174523642
#> 7 0.0168491646 -0.0045347757 -0.0031700407 -0.004811551 0.0014994115
#> 8 0.0233337884 -0.0048729272 -0.0103730486 -0.013344646 -0.0019811544
#> 9 0.0196518612 0.0041171809 -0.0110802771 0.001503922 -0.0017691999
#> 10 0.0136130866 -0.0013651835 0.0039647383 -0.009450711 0.0002169385
#> 2018-03-16 2018-03-19 2018-03-20 2018-03-21 2018-03-22
#> 1 0.0132482035 -0.017800963 0.0140539214 0.0342080617 -0.020780419
#> 2 0.0057620794 -0.012283948 0.0015326711 0.0029637538 -0.030345295
#> 3 0.0097049111 0.019514583 0.0208551086 -0.0027051587 -0.027125637
#> 4 0.0067465768 -0.007155659 -0.0036677505 -0.0090931253 -0.002382522
#> 5 -0.0014468421 -0.016598858 -0.0159511816 0.0009111288 -0.018445826
#> 6 0.0128058372 -0.015527328 -0.0109413440 -0.0031234864 -0.010070408
#> 7 0.0025664048 -0.008129643 0.0038283966 -0.0027663263 -0.023592091
#> 8 0.0072818203 -0.008545107 0.0005299866 0.0028048163 -0.040158724
#> 9 -0.0004359307 -0.019334763 0.0042849448 -0.0010661842 -0.027273994
#> 10 0.0082006855 -0.007323849 0.0042209593 -0.0031006908 -0.019488451
#> 2018-03-23 2018-03-26 2018-03-27 2018-03-28 2018-03-29 2018-04-02
#> 1 -0.006762689 0.01869013 -0.013587364 -0.0241815069 0.023708555 -0.02384333
#> 2 -0.020671257 0.02428748 -0.013607394 -0.0052102103 0.017859557 -0.02556097
#> 3 -0.009710624 0.03912620 -0.023544773 0.0047842311 0.011903628 -0.07048753
#> 4 -0.013253897 0.01174329 0.009301777 0.0115109479 0.003864247 -0.01386817
#> 5 -0.019603345 0.01790434 -0.004012335 0.0077864280 0.006100777 -0.02219502
#> 6 0.005586658 0.02901152 -0.004907839 -0.0061949106 0.004764184 -0.02008524
#> 7 -0.015863577 0.02201133 -0.012779723 -0.0005986344 0.011692887 -0.01812655
#> 8 -0.033051565 0.03536920 -0.021159480 0.0001888029 0.014369638 -0.02507659
#> 9 -0.027953986 0.03558076 -0.036691024 -0.0127492679 0.019706327 -0.03027664
#> 10 -0.011026993 0.02666101 -0.011269919 0.0033580517 0.015304763 -0.02451768
#> 2018-04-03 2018-04-04 2018-04-05 2018-04-06 2018-04-09 2018-04-10
#> 1 0.019486383 0.0008065077 0.019815487 -0.022107520 0.0025333819 0.03916040
#> 2 0.014715841 0.0115904929 0.010750231 -0.027596936 -0.0013867491 0.01671778
#> 3 0.005973514 0.0250603560 -0.004025489 -0.074625383 0.1127089982 -0.01637146
#> 4 0.006779156 0.0100189261 0.002128531 -0.007286219 -0.0002659433 -0.00354477
#> 5 0.010573408 0.0168262644 0.003888427 -0.016300976 0.0006668385 0.01251590
#> 6 0.034235146 0.0327929895 -0.010307551 -0.018687501 -0.0107724779 0.01111685
#> 7 0.011368407 0.0089518300 0.005310227 -0.020248669 0.0039530326 0.01337158
#> 8 0.014514244 0.0115674879 0.006445418 -0.028473234 0.0060287051 0.01701159
#> 9 0.011091022 0.0153590611 0.001131254 -0.030142060 0.0068904541 0.02864014
#> 10 0.011941497 0.0245527566 0.010908214 -0.021364331 -0.0066578116 0.01662728
#> 2018-04-11 2018-04-12 2018-04-13 2018-04-16 2018-04-17
#> 1 0.0134218012 0.0018882349 0.014021218 0.008889818 0.005828624
#> 2 -0.0071466640 0.0095589639 -0.002515237 0.012322901 0.008572858
#> 3 0.0002919895 0.0094385621 -0.031231907 -0.069950239 0.002567647
#> 4 -0.0007258075 -0.0116922688 0.005843584 0.008824431 0.008071086
#> 5 -0.0059624297 0.0023023998 -0.002116732 0.013521629 0.008258630
#> 6 0.0194276384 0.0102286064 -0.024313246 0.001783420 -0.009204711
#> 7 -0.0047569307 0.0068326103 -0.002144741 0.011259635 0.008219502
#> 8 -0.0124702068 0.0187358687 -0.014549366 0.006392001 -0.005228799
#> 9 -0.0057755927 0.0152748724 -0.006289212 0.005107120 0.026027200
#> 10 -0.0065070155 0.0006261891 -0.013650122 0.008475915 0.006776166
#> 2018-04-18 2018-04-19 2018-04-20 2018-04-23 2018-04-24
#> 1 0.0209803229 0.001987134 -0.003255698 0.0051119198 -0.015570104
#> 2 0.0099686724 -0.010952613 -0.006941401 -0.0004020304 -0.021116335
#> 3 -0.0124853059 -0.025826658 -0.043704969 -0.0088157059 -0.011000527
#> 4 -0.0041866844 -0.011586026 -0.012086509 0.0012062362 0.003911963
#> 5 -0.0009691888 -0.012196601 -0.011894216 0.0062815660 -0.005058383
#> 6 -0.0167710481 -0.015619790 -0.015123451 0.0353373495 0.007331051
#> 7 0.0015039281 -0.002994698 -0.004478610 0.0007673909 -0.011855198
#> 8 -0.0009129215 0.016755237 0.001144140 0.0024502710 -0.003212332
#> 9 -0.0001925461 -0.018897988 -0.010199111 -0.0071034281 -0.016939156
#> 10 0.0005093188 -0.009936155 -0.011820071 0.0153302777 -0.001127297
#> 2018-04-25 2018-04-26 2018-04-27 2018-04-30 2018-05-01
#> 1 6.257147e-03 0.0119568379 -0.0100034081 0.000785677 -0.005264935
#> 2 6.736282e-03 -0.0059074636 0.0009474261 -0.015695753 0.002021579
#> 3 -2.271928e-02 0.0193728790 -0.0062952606 0.000000000 0.005498434
#> 4 5.395037e-05 0.0110083812 0.0127658727 -0.005845951 0.001892285
#> 5 8.836164e-03 0.0002847735 -0.0015254802 -0.012112274 -0.001784067
#> 6 -2.038064e-02 0.0251171389 0.0301978798 0.014655499 -0.002154140
#> 7 1.048921e-03 0.0050302227 0.0023543514 -0.008048128 0.001261753
#> 8 -8.194749e-04 0.0014155280 0.0074304687 -0.011858982 -0.002134304
#> 9 -4.806665e-03 0.0257372537 -0.0064280065 -0.005138238 0.013484231
#> 10 6.889402e-03 0.0320344375 0.0133433562 -0.012735289 -0.013002988
#> 2018-05-02 2018-05-03 2018-05-04 2018-05-07 2018-05-08
#> 1 0.009021952 -0.0036174070 0.007982274 0.0002968910 0.0105907631
#> 2 -0.007293515 0.0001890548 0.011767646 0.0016470808 0.0043503749
#> 3 0.014146397 -0.0300081826 -0.067069523 0.0202073194 -0.0083799388
#> 4 -0.007684412 0.0011809787 0.010283303 -0.0009191323 -0.0131161149
#> 5 -0.012658796 -0.0197507981 0.018466776 -0.0040066535 -0.0131674013
#> 6 0.001715860 -0.0356584363 0.005718492 0.0262778717 0.0040248183
#> 7 -0.012132110 -0.0004455295 0.009236322 0.0023215080 0.0008205109
#> 8 -0.015829563 -0.0103559062 0.015932978 0.0061273534 0.0047754632
#> 9 -0.004583453 0.0074488279 0.017274560 0.0098316368 0.0036974782
#> 10 -0.001480742 -0.0084251189 0.003012113 -0.0094507256 0.0042875069
#> 2018-05-09 2018-05-10 2018-05-11 2018-05-14 2018-05-15
#> 1 0.019081795 0.002484973 -2.105145e-03 0.0057834594 0.003230659
#> 2 0.007346739 0.008275428 1.437453e-03 0.0003666706 -0.004829891
#> 3 -0.003457055 -0.006938211 2.781732e-02 0.0187562684 0.030520227
#> 4 0.001706413 0.009265730 -9.737764e-04 -0.0059797035 -0.012241363
#> 5 0.002195217 0.016548100 6.851217e-03 0.0018401981 -0.007666763
#> 6 -0.013015150 -0.002490280 9.526900e-03 -0.0220298167 0.026932336
#> 7 0.005407329 0.008811339 -7.157434e-04 -0.0007310390 -0.005346392
#> 8 0.010309673 0.007576544 1.257945e-03 0.0000384929 0.001126507
#> 9 0.021007444 0.012657333 -9.617619e-05 0.0020080256 -0.008358058
#> 10 0.006855169 -0.004103176 8.769280e-03 0.0072741919 0.004826529
#> 2018-05-16 2018-05-17 2018-05-18 2018-05-21 2018-05-22
#> 1 0.008030031 2.104331e-02 -0.006194309 0.008416722 -0.013949927
#> 2 0.009172102 4.123888e-03 0.003438637 0.008690897 -0.009710431
#> 3 0.028776990 -7.657342e-02 0.076612391 -0.021453716 -0.018210183
#> 4 -0.003090867 -5.560361e-03 -0.004341187 0.006627933 0.003319260
#> 5 0.009320814 -2.413515e-03 -0.005069944 -0.002153219 0.001258431
#> 6 0.053727542 -1.703862e-02 -0.006411297 -0.005686704 -0.005045261
#> 7 0.003422726 5.045988e-05 0.001997108 0.006466379 -0.006352082
#> 8 0.002558516 4.832637e-03 -0.008123400 0.004794623 0.007862453
#> 9 0.005683026 -3.396801e-03 -0.003809872 0.007006359 -0.001167281
#> 10 0.012650264 4.609209e-03 -0.005808795 0.006947448 -0.013971087
#> 2018-05-23 2018-05-24 2018-05-25 2018-05-29 2018-05-30
#> 1 -0.003799118 -1.286371e-02 -0.0273864394 -0.001655917 0.028824217
#> 2 -0.001215370 5.943826e-05 0.0007037725 -0.014488437 0.009966459
#> 3 0.010372252 -2.681161e-02 -0.0076942540 -0.026638282 0.035590337
#> 4 0.008864209 8.249051e-04 0.0055005368 0.002300602 0.011410992
#> 5 -0.005902130 -2.844831e-03 0.0014090191 -0.012097902 0.009750346
#> 6 0.004396211 1.052968e-02 0.0126268356 -0.010898882 0.024874911
#> 7 0.001980473 1.381910e-03 -0.0018404690 -0.011661328 0.013319953
#> 8 -0.007788370 -4.284822e-03 -0.0056191330 -0.038774079 0.019770315
#> 9 0.006338701 1.349088e-03 -0.0001295464 -0.005308372 0.008013739
#> 10 0.026624971 7.949624e-03 -0.0006711770 -0.001536402 0.010278605
#> 2018-05-31 2018-06-01 2018-06-04 2018-06-05 2018-06-06
#> 1 -0.0121672609 0.002045573 -0.012513933 -0.0024687159 0.003589474
#> 2 -0.0113469693 0.010495083 0.002494881 0.0034657119 0.011874420
#> 3 -0.0040943053 0.125576198 -0.418151620 0.0644854290 0.071837046
#> 4 -0.0063160337 -0.004395287 0.002833296 -0.0054107634 -0.006994175
#> 5 -0.0108755519 0.003768814 0.004091356 0.0008772653 0.013741639
#> 6 -0.0129728466 0.012788744 0.038638682 0.0091358159 0.025319769
#> 7 -0.0095870912 0.009473243 0.006387099 0.0025827292 0.009697714
#> 8 -0.0067783550 0.013814430 0.003368935 -0.0042688724 0.019197647
#> 9 -0.0008890349 0.022679037 0.009370188 0.0074432858 0.005554430
#> 10 -0.0209360375 0.012156052 0.019754701 0.0177734116 0.004464315
#> 2018-06-07 2018-06-08 2018-06-11 2018-06-12 2018-06-13
#> 1 0.0168976076 -0.005089168 0.005802034 -0.004957193 -0.003041303
#> 2 0.0011867260 0.005447637 0.003810804 0.001637788 -0.009294020
#> 3 -0.1168722741 0.022087936 -0.020687089 0.010184855 -0.001680358
#> 4 0.0024689257 0.005029354 0.001084370 0.008286966 -0.011036649
#> 5 0.0043192493 0.006933643 0.009676922 0.002799132 0.003313122
#> 6 -0.0021533389 0.034115404 0.001842297 0.006478598 -0.011782038
#> 7 -0.0001199133 0.005976695 -0.001170107 0.002111238 -0.004617059
#> 8 -0.0005056904 0.003260364 -0.003454057 -0.003001729 -0.006034655
#> 9 -0.0130480661 0.003009932 0.002501295 0.008744624 0.002490950
#> 10 0.0036871882 0.007225727 0.006170351 0.005481649 -0.010064940
#> 2018-06-14 2018-06-15 2018-06-18 2018-06-19 2018-06-20
#> 1 -4.950259e-03 -0.0233421646 1.725029e-02 0.0009711716 0.0104862440
#> 2 2.346836e-03 -0.0014502131 -3.203424e-03 -0.0158695041 0.0013754952
#> 3 5.498408e-02 0.0257046800 9.505686e-03 -0.0179763568 0.0141212864
#> 4 9.677993e-03 0.0051368551 -2.855371e-03 0.0061054144 0.0046159044
#> 5 1.307883e-02 0.0080650764 -1.083052e-02 0.0059046333 0.0112189975
#> 6 6.708171e-03 -0.0049014024 -2.150519e-03 -0.0198213640 0.0156183786
#> 7 8.440334e-05 0.0016942832 -2.079763e-03 -0.0049102162 -0.0022890739
#> 8 -6.424824e-03 -0.0004686897 -9.139113e-04 -0.0023326027 -0.0005223572
#> 9 1.039053e-02 -0.0011952428 -3.632523e-05 -0.0064698075 0.0054185685
#> 10 -6.319777e-03 0.0071999880 7.523292e-03 -0.0050496552 0.0052552417
#> 2018-06-21 2018-06-22 2018-06-25 2018-06-26 2018-06-27
#> 1 -0.023013302 0.024528376 -0.026993165 0.0179577088 0.0160728586
#> 2 -0.012317685 0.004047323 -0.016300246 0.0003925465 -0.0091149222
#> 3 -0.039711141 -0.053884765 -0.029895895 -0.0284766725 -0.0714716107
#> 4 0.004419211 0.008532335 0.010974704 0.0002788998 -0.0007296724
#> 5 -0.006190287 0.007151838 -0.006624295 -0.0029080196 -0.0036461386
#> 6 -0.005137809 -0.002430153 -0.008138573 0.0027829492 -0.0058557019
#> 7 -0.004769932 0.002707633 -0.011117660 -0.0007922268 -0.0102439714
#> 8 -0.001628419 -0.005297907 -0.011876749 -0.0077799474 -0.0180782807
#> 9 -0.009342208 -0.007652501 -0.026071675 0.0055241982 -0.0213655367
#> 10 0.006276093 -0.015094814 -0.009493673 0.0053312138 -0.0123244723
#> 2018-06-28 2018-06-29 2018-07-02 2018-07-03 2018-07-05
#> 1 -0.0030642273 0.0066213840 -0.0172210767 0.0095253240 -1.767987e-03
#> 2 -0.0008224507 0.0028916577 -0.0008781831 -0.0031883081 8.944781e-03
#> 3 0.0421621838 0.0130705599 0.0000000000 -0.0167930364 -9.789565e-03
#> 4 0.0073889078 0.0006889191 -0.0024812634 0.0041746241 1.179255e-02
#> 5 -0.0024405481 -0.0027333176 -0.0008492784 0.0007726969 1.141184e-02
#> 6 0.0039705827 -0.0150809026 -0.0009759573 0.0020310113 9.359615e-05
#> 7 0.0070371261 0.0020066487 0.0024962374 -0.0006873148 7.202007e-03
#> 8 0.0042289102 -0.0029578166 0.0077655467 -0.0090663874 1.902414e-03
#> 9 0.0110192846 0.0043957571 0.0098585427 -0.0127259939 1.572207e-02
#> 10 0.0039341038 -0.0078641190 -0.0061327457 0.0042747254 1.661094e-03
#> 2018-07-06 2018-07-09 2018-07-10 2018-07-11 2018-07-12
#> 1 0.013230379 0.019348406 0.0035448367 -0.024326016 4.090626e-05
#> 2 0.004085516 0.016470829 0.0023252625 -0.017387717 6.668402e-03
#> 3 0.002103450 -0.001889169 -0.0090431127 -0.007640089 1.946108e-02
#> 4 0.004636470 -0.017768040 0.0066470763 0.003459740 5.239076e-04
#> 5 0.017406371 0.007780730 0.0002461581 -0.009658975 3.446156e-03
#> 6 0.007841180 0.003569912 0.0099024402 -0.016783131 -7.701430e-03
#> 7 0.006132032 0.010114855 0.0032847745 -0.003593779 8.512059e-03
#> 8 0.005321490 0.026350690 -0.0062570640 -0.009160786 -2.599485e-03
#> 9 0.013600114 0.005709863 0.0034480789 -0.007515485 1.908716e-02
#> 10 0.007425574 0.007631400 0.0034885779 -0.010433248 -4.363527e-03
#> 2018-07-13 2018-07-16 2018-07-17 2018-07-18 2018-07-19
#> 1 4.867876e-03 -0.014807417 -0.0022767025 0.001214596 -0.002012756
#> 2 5.235608e-03 -0.007084843 0.0080887547 0.007209239 0.001933292
#> 3 2.517370e-03 0.000000000 0.0119271812 -0.009925558 0.025062677
#> 4 1.874274e-05 -0.004256369 -0.0027140568 -0.007055234 0.009712834
#> 5 2.669626e-03 -0.005283623 -0.0065694222 -0.004587763 -0.003762141
#> 6 -1.541857e-02 -0.003578053 -0.0005944396 -0.009222596 0.005481916
#> 7 8.325806e-04 -0.003616864 0.0052730498 0.003865291 -0.001972146
#> 8 -7.159351e-03 0.012598295 0.0043159256 0.015016303 -0.015162640
#> 9 -2.652942e-03 -0.002394465 0.0100067061 0.002875424 -0.006342116
#> 10 4.434888e-03 0.003577212 0.0073994359 0.001621313 0.014010529
#> 2018-07-20 2018-07-23 2018-07-24 2018-07-25 2018-07-26
#> 1 -0.0034620002 -0.0034233673 0.0102084510 0.0078325140 0.0135305137
#> 2 -0.0034162131 -0.0055206191 0.0023507571 0.0083359617 0.0096650627
#> 3 -0.0071312548 0.0131335727 -0.0589426789 0.0725355806 0.0064218340
#> 4 -0.0062096796 -0.0045346308 -0.0001479598 0.0066579812 0.0086039070
#> 5 -0.0066459716 0.0016235432 -0.0013017226 0.0032500436 -0.0025782781
#> 6 -0.0056548335 0.0049671313 -0.0244801448 0.0069277697 0.0121349973
#> 7 -0.0001084197 0.0006892011 -0.0007583416 0.0121278133 0.0017179854
#> 8 -0.0022476698 0.0157739015 0.0016265131 -0.0003614201 -0.0002047844
#> 9 -0.0039916776 0.0017171076 -0.0064646147 0.0142021945 -0.0030455166
#> 10 -0.0052198993 0.0045753947 -0.0121882429 0.0085691153 0.0020772885
#> 2018-07-27 2018-07-30 2018-07-31 2018-08-01 2018-08-02
#> 1 0.0014546713 0.013222113 -0.0027140426 -0.0161653379 -0.0026196342
#> 2 -0.0008966617 -0.004236450 0.0155806867 -0.0133384042 0.0007723577
#> 3 0.0075772081 0.009895112 0.0307661970 0.0020912738 0.0301650546
#> 4 -0.0057343847 -0.002607408 0.0138063655 -0.0028345019 0.0043042312
#> 5 -0.0041296590 0.005629008 0.0074027777 -0.0072752292 0.0029011263
#> 6 -0.0344818122 -0.012369755 0.0023765964 -0.0263066435 0.0179087830
#> 7 -0.0065698203 -0.009659305 0.0082086411 -0.0007021521 0.0041786003
#> 8 0.0053453093 0.001904713 -0.0029612366 -0.0037971441 -0.0015952817
#> 9 -0.0217630766 -0.023228530 0.0012193522 0.0010969962 0.0147379276
#> 10 -0.0124641857 0.004916835 0.0007446667 -0.0231840308 0.0141771090
#> 2018-08-03 2018-08-06 2018-08-07 2018-08-08 2018-08-09
#> 1 -0.010233940 0.0050239144 0.004059245 -0.0088304597 -0.011146325
#> 2 0.007919865 0.0018865369 0.004700065 -0.0035467835 -0.001621424
#> 3 -0.006629834 0.0268817209 -0.013901427 0.0245331385 0.060936384
#> 4 0.012873725 0.0002266594 -0.003832789 -0.0043559555 0.001524320
#> 5 0.015055349 0.0005402166 -0.005266106 -0.0072529766 0.005185337
#> 6 0.011616620 -0.0065698148 -0.003229978 0.0053762910 -0.005674625
#> 7 0.001366183 0.0021993749 0.002973420 -0.0005313402 -0.001324354
#> 8 0.003872503 0.0013262833 0.004371695 0.0030043987 -0.006755802
#> 9 0.001297297 0.0071028279 0.003605434 0.0002292512 -0.002651602
#> 10 0.001037369 0.0041604422 0.008444286 0.0085681784 0.007913891
#> 2018-08-10 2018-08-13 2018-08-14 2018-08-15 2018-08-16 2018-08-17
#> 1 0.008197005 -0.0148045474 0.004164327 -0.043252247 0.006158433 0.002742595
#> 2 -0.010985125 -0.0097350386 0.007439660 -0.006183594 0.008502705 0.007306792
#> 3 0.006400556 -0.0073640000 0.018209374 -0.029309489 0.022688537 0.001334412
#> 4 -0.005342456 0.0009719751 0.003529508 0.009325750 0.009226345 0.008078485
#> 5 -0.007442825 0.0020533036 0.010328821 -0.005398462 0.013826139 0.005681307
#> 6 -0.006707002 -0.0011200654 0.012016787 -0.032090836 0.006257623 0.008883416
#> 7 -0.006326996 -0.0028082368 0.006857404 -0.002822767 0.006583832 0.004348640
#> 8 -0.015638998 -0.0081579241 0.013580302 -0.008622291 0.014895499 0.001659169
#> 9 -0.010200435 -0.0019347591 0.006603682 -0.015252216 0.003003307 -0.001837494
#> 10 -0.001972391 -0.0080907188 0.027171989 -0.023489566 0.004748954 0.014589614
#> 2018-08-20 2018-08-21 2018-08-22 2018-08-23 2018-08-24
#> 1 8.602273e-03 0.008262139 0.0139055373 -0.0055045671 0.008267983
#> 2 8.524252e-03 0.008757678 -0.0090557179 -0.0062899220 0.005617281
#> 3 9.495236e-03 0.022442261 0.0182375891 0.0066571247 0.005983326
#> 4 -1.900039e-05 -0.009680688 -0.0073255439 -0.0009873718 0.005195784
#> 5 3.803443e-03 0.005795501 -0.0061483081 -0.0047590768 0.001428455
#> 6 1.914385e-02 -0.007776288 0.0065063175 -0.0019539588 0.004117846
#> 7 2.979135e-03 0.001429279 -0.0002109145 -0.0016070430 0.005108551
#> 8 4.525031e-03 0.005591879 -0.0019818298 -0.0092653369 0.002762638
#> 9 1.668143e-03 0.007931618 0.0081557305 0.0029850589 0.017675717
#> 10 1.588253e-02 0.005609392 -0.0021440605 0.0042049829 -0.008546296
#> 2018-08-27 2018-08-28 2018-08-29 2018-08-30 2018-08-31
#> 1 0.008941696 -0.0055103468 0.007477945 -0.002647283 -0.0075750381
#> 2 0.014400185 -0.0004318317 0.003482338 -0.010293555 -0.0011595493
#> 3 0.020817061 0.0136461206 0.009680820 -0.011235955 0.0074242121
#> 4 -0.003971634 0.0022368854 0.002586546 -0.002759299 0.0007757062
#> 5 0.005035947 -0.0008977586 0.004427884 -0.006345992 0.0006697291
#> 6 -0.012434286 0.0183920291 0.010118890 -0.015824365 -0.0105498117
#> 7 0.004644889 0.0003135864 0.004871695 -0.003858023 0.0025254035
#> 8 0.012982398 -0.0008705840 -0.002040786 -0.009952109 0.0003218929
#> 9 0.010707135 0.0031534967 0.007478941 -0.005572729 0.0004631992
#> 10 -0.006417500 0.0008250578 0.001488313 -0.016775669 0.0107940404
#> 2018-09-04 2018-09-05 2018-09-06 2018-09-07 2018-09-10
#> 1 -0.0070592750 -0.004888021 -0.019724100 -4.883160e-03 0.0001684534
#> 2 -0.0035987329 0.006790031 -0.003093572 -4.258797e-03 0.0079611455
#> 3 0.0300797121 -0.013578625 -0.023090557 -1.515152e-02 0.0243077231
#> 4 -0.0020224432 0.010913473 0.005815731 -9.105094e-03 0.0057552048
#> 5 -0.0120022215 0.003809216 -0.002024138 -8.473313e-06 0.0013504967
#> 6 0.0037820465 -0.006230806 0.002126863 -1.155581e-02 0.0096196319
#> 7 -0.0004285138 -0.001921624 0.004131752 -1.337027e-03 0.0010736121
#> 8 0.0040865301 0.002150200 -0.010369325 -3.209852e-03 -0.0002207457
#> 9 -0.0020112376 -0.018580855 -0.011470161 -3.122961e-03 0.0065329599
#> 10 0.0090589522 -0.002634218 -0.000610998 -2.435663e-03 0.0095841030
#> 2018-09-11 2018-09-12 2018-09-13 2018-09-14 2018-09-17
#> 1 0.0125906552 0.0094216237 9.934933e-05 0.0044610842 0.0007565535
#> 2 0.0009130264 0.0023031503 4.296344e-03 0.0048152947 -0.0005478927
#> 3 -0.0325923391 -0.0245303820 -1.480185e-02 -0.0428110164 -0.0158649620
#> 4 -0.0016248564 0.0020770529 5.488479e-03 -0.0065181328 0.0044735104
#> 5 -0.0036985013 0.0138667133 8.487749e-03 -0.0032909437 -0.0004594928
#> 6 -0.0048945618 0.0092948871 -9.913287e-03 -0.0210201443 0.0116812773
#> 7 0.0012624806 0.0016374196 8.553440e-03 0.0012615991 -0.0051405746
#> 8 0.0012947111 -0.0120416158 -4.999120e-03 0.0118714595 -0.0068291246
#> 9 0.0017926979 -0.0022187221 8.009300e-03 0.0033791890 -0.0180158502
#> 10 0.0018000222 0.0008785819 -1.058478e-02 -0.0001800824 -0.0057614177
#> 2018-09-18 2018-09-19 2018-09-20 2018-09-21 2018-09-24
#> 1 0.0114705801 0.002798174 -0.0043917559 8.309258e-03 0.014519942
#> 2 0.0049761950 0.005135099 0.0056715041 -5.909433e-04 -0.015135406
#> 3 0.0003430115 -0.028115943 0.0308696425 9.582495e-03 0.031694898
#> 4 -0.0063531947 -0.014233984 0.0063179378 2.562292e-03 -0.014799505
#> 5 0.0031411987 0.002407114 0.0086177181 -1.450535e-05 -0.008483643
#> 6 0.0011495417 -0.002418902 0.0358724217 1.464962e-02 -0.005450741
#> 7 0.0067298580 -0.002218726 0.0054453566 2.156660e-03 -0.005210554
#> 8 0.0045740814 0.018599329 0.0121824641 -1.329279e-03 -0.013335200
#> 9 0.0106929306 -0.002237771 0.0118807027 -2.181430e-03 0.008367619
#> 10 0.0064143810 0.002846331 -0.0001757148 1.407939e-03 -0.011390935
#> 2018-09-25 2018-09-26 2018-09-27 2018-09-28 2018-10-01
#> 1 0.0085246357 -0.009883996 -0.0004367765 0.0007319574 0.0139511626
#> 2 -0.0062096321 -0.004361171 -0.0035803046 -0.0027209147 0.0026813932
#> 3 0.0044356827 -0.026496549 0.0233534946 0.0008208669 -0.0707020517
#> 4 -0.0061245666 -0.009566338 0.0009599424 0.0131846709 -0.0051654815
#> 5 -0.0059697355 0.004027241 0.0043660961 0.0008865426 0.0012467781
#> 6 -0.0087824800 0.011815491 -0.0028367799 0.0006963594 0.0023327520
#> 7 -0.0002905777 -0.002750915 0.0010664761 0.0024383750 0.0009372752
#> 8 -0.0053299605 -0.014376826 -0.0051507609 -0.0079691640 0.0014877535
#> 9 -0.0005526985 -0.003000878 0.0066080156 0.0028804017 -0.0028228503
#> 10 -0.0003542208 0.011888628 -0.0014428506 0.0015011095 -0.0041500247
#> 2018-10-02 2018-10-03 2018-10-04 2018-10-05 2018-10-08
#> 1 -0.0018745900 0.0140702266 -0.0075792794 -0.0020717943 -0.0049331277
#> 2 -0.0007192967 0.0008544285 -0.0068644051 -0.0143323602 0.0005466162
#> 3 -0.0233009701 -0.0280137890 -0.0310523992 0.0057570331 -0.0124022515
#> 4 0.0051680363 -0.0111430061 0.0004933203 0.0073847854 0.0120161932
#> 5 0.0067763755 -0.0003061440 -0.0038010313 -0.0034132009 0.0080274136
#> 6 -0.0292476393 0.0012603126 -0.0465294258 -0.0086338916 0.0044601527
#> 7 -0.0016157409 -0.0020186796 -0.0075101510 -0.0014388058 -0.0018125260
#> 8 -0.0004600591 0.0135710864 0.0071106813 -0.0066480633 0.0061169843
#> 9 -0.0071298716 0.0023750307 -0.0233235260 -0.0176794913 -0.0177103382
#> 10 -0.0229407256 0.0030379015 -0.0156392847 -0.0004590578 0.0100873473
#> 2018-10-09 2018-10-10 2018-10-11 2018-10-12 2018-10-15
#> 1 0.0124229185 -0.04097909 -0.025782633 0.0059888499 -0.0060934752
#> 2 -0.0248496552 -0.03159005 -0.021253444 0.0037968000 -0.0005190411
#> 3 0.0038640071 -0.06408772 -0.015011289 0.0210855524 0.0034758127
#> 4 0.0020736921 -0.01013827 -0.024421821 0.0009588859 0.0065783940
#> 5 -0.0016443597 -0.01799719 -0.028472345 0.0093620834 0.0048798307
#> 6 -0.0020867178 -0.04497825 -0.006234847 0.0165520824 0.0047664216
#> 7 -0.0008205698 -0.03058480 -0.020450426 0.0112629390 -0.0003980468
#> 8 -0.0069734420 -0.02789570 -0.032854462 -0.0035857475 -0.0033363777
#> 9 -0.0016138833 -0.04752720 -0.009528649 0.0317364880 -0.0133225512
#> 10 -0.0033571614 -0.03091620 -0.010680525 0.0221345526 0.0058508853
#> 2018-10-16 2018-10-17 2018-10-18 2018-10-19 2018-10-22
#> 1 0.01115067 -0.0124540861 -0.0114582006 -0.013417791 -0.010410421
#> 2 0.02029746 -0.0076945146 -0.0231302093 -0.006500575 -0.007068358
#> 3 0.02832109 0.0023776302 -0.0203597351 -0.027643300 -0.172234907
#> 4 0.01521553 -0.0020019157 0.0007101897 0.014616273 -0.009863440
#> 5 0.01975858 0.0039252142 -0.0051469232 0.007457300 -0.011459308
#> 6 0.02948928 -0.0119113046 -0.0305859004 -0.017219189 0.007156364
#> 7 0.02211807 0.0003522718 -0.0103212858 -0.005394535 -0.001723674
#> 8 0.01034178 0.0085457687 -0.0201742370 0.003795141 -0.026631828
#> 9 0.03521865 0.0008375004 -0.0223033731 -0.012288437 0.006961321
#> 10 0.01710068 -0.0203790064 -0.0102005636 -0.016339023 0.010879318
#> 2018-10-23 2018-10-24 2018-10-25 2018-10-26 2018-10-29 2018-10-30
#> 1 -0.029362516 -0.04562188 0.014966109 -0.0103189656 -0.025214074 0.02332618
#> 2 -0.007092987 -0.03570604 0.023356378 -0.0148907828 -0.006224548 0.02816530
#> 3 -0.009776862 -0.07316453 0.004370363 0.0008158553 -0.006249973 0.02570407
#> 4 0.001911286 0.01528583 -0.003102589 -0.0203130185 0.015054345 0.01043888
#> 5 -0.003311928 -0.03903726 0.005090339 -0.0199204871 0.009917465 0.01753953
#> 6 -0.005566678 -0.02012756 0.016094313 -0.0311337726 0.001037755 0.14925401
#> 7 -0.008607753 -0.02597772 0.010779794 -0.0088856802 -0.004867729 0.01495025
#> 8 -0.005366016 -0.03467107 0.020370074 -0.0183638394 0.007990397 0.01949656
#> 9 -0.002123629 -0.05350617 0.029149480 -0.0251540714 -0.020434232 0.02836827
#> 10 -0.002233431 -0.01785801 0.016199598 -0.0057243680 0.029929712 0.01954942
#> 2018-10-31 2018-11-01 2018-11-02 2018-11-05 2018-11-06
#> 1 0.006816483 0.009901865 -0.0109428618 0.018555781 0.0014621014
#> 2 0.010098708 0.030861240 0.0004294791 0.003012493 0.0135847704
#> 3 0.031191737 0.051964814 -0.0403047442 0.024327811 -0.0979999500
#> 4 -0.014055138 0.003469638 -0.0086105882 0.015065251 0.0089221744
#> 5 0.003367997 0.017157149 -0.0143544530 0.011240377 0.0056355213
#> 6 -0.020619102 0.051989082 0.0121737492 0.001490086 -0.0100087193
#> 7 0.010817368 0.006399525 0.0004950808 0.006240543 0.0055197936
#> 8 0.013075842 0.011193448 -0.0016310760 0.008834670 0.0066328269
#> 9 0.023048845 0.030616530 -0.0079101802 -0.006904578 0.0067142368
#> 10 -0.007517953 0.011497286 0.0086827077 0.009871627 0.0008205707
#> 2018-11-07 2018-11-08 2018-11-09 2018-11-12 2018-11-13
#> 1 0.022763584 -0.0279779331 -0.003977968 -0.028896189 -0.025667390
#> 2 0.016644820 -0.0059255010 -0.014389669 -0.016491823 0.004996446
#> 3 0.051829238 -0.0695652156 -0.036533587 0.087301646 0.009732251
#> 4 0.008456520 0.0006626919 0.005734313 0.001970723 0.001387374
#> 5 0.015334432 -0.0038562883 -0.008833036 -0.006459755 -0.002891639
#> 6 -0.061400220 -0.0175014576 -0.003424412 0.003733015 -0.010312611
#> 7 0.019408417 0.0016667421 -0.002407997 -0.016533978 -0.003089991
#> 8 0.011117884 0.0020460200 -0.010078793 -0.017629228 0.005880597
#> 9 0.028741090 0.0011837278 -0.026533606 -0.040657999 0.003822394
#> 10 0.002686674 0.0125439971 -0.014677606 -0.009050224 0.001460708
#> 2018-11-14 2018-11-15 2018-11-16 2018-11-19 2018-11-20
#> 1 0.003056712 0.0204367796 0.0087739207 -0.005510447 -0.040142811
#> 2 -0.002768186 0.0130204291 0.0030213262 -0.013364418 -0.017910934
#> 3 0.008032236 0.0143425490 0.0010474208 -0.005754695 0.002894002
#> 4 -0.003968489 -0.0046827359 0.0107219718 0.002030012 -0.007016541
#> 5 -0.006680480 0.0009516148 0.0002236666 -0.008997463 -0.020629842
#> 6 0.008997432 0.0049399759 -0.0030274281 -0.023873696 -0.025369756
#> 7 -0.006670144 0.0116369279 0.0067402419 -0.015567541 -0.013064750
#> 8 -0.014107766 0.0129622049 -0.0035958448 -0.002917412 -0.020750162
#> 9 -0.006290939 0.0250978123 -0.0047271059 -0.047032801 -0.005977836
#> 10 -0.013310246 -0.0125685232 -0.0116833017 -0.018725644 -0.040683528
#> 2018-11-21 2018-11-23 2018-11-26 2018-11-27 2018-11-28
#> 1 0.019085083 -0.0365977773 0.021449561 -0.006018243 0.016015822
#> 2 0.010441620 -0.0011443963 0.014989363 -0.005379398 0.021022168
#> 3 -0.020199397 -0.0050869615 0.049246555 -0.028212438 0.017418844
#> 4 -0.007205334 0.0002767069 0.001992582 0.006488272 0.001633862
#> 5 0.004695085 -0.0033997786 0.008529753 0.009436897 0.018012414
#> 6 0.025140280 0.0013054052 0.024831329 -0.012790536 0.025601171
#> 7 0.003713427 -0.0006914029 0.011219229 -0.001119745 0.022808032
#> 8 0.006652269 -0.0043189544 0.024158785 -0.005284478 0.018002106
#> 9 0.011098152 -0.0043427684 0.027146861 0.002509348 0.032765817
#> 10 0.021905134 -0.0023011150 0.015542793 0.003006949 0.013702128
#> 2018-11-29 2018-11-30 2018-12-03 2018-12-04 2018-12-06
#> 1 6.148792e-03 -0.006325286 0.026717664 -0.034175756 -0.025456988
#> 2 -4.583827e-03 0.008348400 0.014387256 -0.043469158 -0.005599437
#> 3 1.841761e-02 0.028782503 0.003466205 -0.062422873 0.001052658
#> 4 2.199132e-05 0.013052474 0.003942276 -0.006823531 0.010470297
#> 5 1.114787e-03 -0.004001853 0.003912594 -0.023981973 0.000737530
#> 6 9.790854e-03 0.011923396 0.008186916 -0.035915469 0.010435450
#> 7 -1.373260e-03 0.004571330 0.008552870 -0.026274931 -0.005388248
#> 8 -1.124658e-02 0.009000794 0.003082248 -0.052136636 -0.015896970
#> 9 -8.013880e-03 0.007851787 0.022060319 -0.043983311 0.007674433
#> 10 -8.881309e-03 0.003592097 0.012809931 -0.032821006 0.000835305
#> 2018-12-07 2018-12-10 2018-12-11 2018-12-12 2018-12-13
#> 1 -0.006780232 -0.022570773 -1.766926e-03 0.012147228 -0.001884312
#> 2 -0.028208646 -0.006139098 -4.630299e-03 0.007634287 -0.011030741
#> 3 -0.027602497 -0.008921384 -6.273868e-03 0.014822976 0.027860400
#> 4 -0.005780874 -0.000668987 4.809378e-03 -0.010891587 0.009144740
#> 5 -0.018912842 -0.004455976 -2.284799e-03 0.006800195 -0.004737673
#> 6 -0.023800039 -0.030173882 -9.661122e-03 -0.041004302 -0.046881818
#> 7 -0.019984046 0.004405560 -2.228687e-05 0.007237402 -0.002095760
#> 8 -0.020740007 -0.018930524 -1.261705e-02 0.008863699 -0.014106619
#> 9 -0.039234204 0.012720573 2.684961e-03 0.012600918 -0.007303151
#> 10 -0.034276620 0.002452843 -4.247659e-03 0.011143110 -0.017358513
#> 2018-12-14 2018-12-17 2018-12-18 2018-12-19 2018-12-20
#> 1 -0.029336122 -0.019352282 -0.022654426 -0.013204994 -0.028575670
#> 2 -0.009633473 -0.019609241 0.004430270 -0.019222002 -0.015347254
#> 3 -0.039210579 -0.064365876 0.046252986 -0.041410294 -0.047577265
#> 4 -0.004675184 -0.034101645 -0.000472998 -0.004732855 -0.007327090
#> 5 -0.018665145 -0.015789359 -0.014756056 -0.014034106 -0.022073685
#> 6 -0.013733872 -0.039133195 0.005274900 -0.038867541 -0.036916627
#> 7 -0.018439996 -0.019062770 -0.001934337 -0.011227961 -0.018565500
#> 8 -0.013830399 -0.008949145 -0.007170497 -0.019007629 -0.007302266
#> 9 -0.020874974 -0.023941234 0.011680439 -0.029163313 -0.016142801
#> 10 -0.010526239 -0.022412294 0.004111106 -0.018619423 -0.020096893
#> 2018-12-21 2018-12-24 2018-12-26 2018-12-27 2018-12-28
#> 1 -0.015271980 -0.044090019 0.07118951 0.0042271745 -0.0097704415
#> 2 -0.019014858 -0.025740463 0.04904494 0.0094431419 -0.0052368214
#> 3 -0.061599753 -0.006205127 0.07722639 0.0118974683 0.0135665067
#> 4 -0.009893661 -0.041911660 0.02554223 0.0053546526 0.0005053989
#> 5 -0.031031617 -0.020769290 0.04071062 -0.0007565322 0.0001404716
#> 6 -0.045031128 -0.016539024 0.06331100 0.0002329840 -0.0045310636
#> 7 -0.015247631 -0.023742530 0.03961691 0.0137016375 -0.0006260089
#> 8 -0.018998426 -0.019527663 0.05029160 0.0078091181 -0.0014399951
#> 9 -0.028028995 -0.024168568 0.06246057 0.0115646542 -0.0011372936
#> 10 -0.014589913 -0.010947540 0.05443842 0.0021567094 -0.0025467586
#> 2018-12-31 2019-01-02 2019-01-03 2019-01-04 2019-01-07 2019-01-08
#> 1 0.006456026 0.018934200 -0.0068040359 0.04480931 0.020424497 0.011914149
#> 2 0.008235904 0.007674563 -0.0287565498 0.04270896 0.010646452 0.013287479
#> 3 -0.022308151 0.041070947 -0.0771478937 0.07536412 0.078327446 0.110868408
#> 4 0.003151921 -0.019649719 0.0040544863 0.01122349 0.004258097 0.015108576
#> 5 0.005502644 0.011648676 0.0009514952 0.03025055 0.010807924 0.011562557
#> 6 0.008908671 0.015416813 -0.0317893837 0.06518064 0.047956588 0.015403992
#> 7 0.011195438 -0.009432451 -0.0247124773 0.03118747 0.003744972 0.009879408
#> 8 0.008343250 0.015789745 -0.0156475488 0.03863878 0.005650392 0.002605368
#> 9 0.008236568 0.002011376 -0.0428379750 0.04790346 0.020832316 0.007710849
#> 10 0.012570567 0.007893225 -0.0119779942 0.01823873 0.029259172 0.010813279
#> 2019-01-09 2019-01-10 2019-01-11 2019-01-14 2019-01-15
#> 1 0.0214663195 0.0070154418 -0.0051453937 -0.0001068403 0.0045448116
#> 2 0.0107302444 0.0073629924 0.0013346987 -0.0029861793 -0.0046655977
#> 3 0.0122910521 0.0070422778 -0.0110924280 0.0124360406 0.0722543353
#> 4 -0.0046266730 0.0148200525 0.0004690556 -0.0076883127 0.0119218564
#> 5 -0.0002021558 0.0072119147 0.0039341056 -0.0038065143 0.0053050647
#> 6 0.0024858505 -0.0012238388 0.0196272284 0.0011025999 0.0090727502
#> 7 0.0030176941 0.0080709773 0.0011915460 -0.0055073864 0.0111375049
#> 8 0.0100042782 -0.0004827736 0.0030250262 0.0080313866 0.0092033433
#> 9 0.0183498240 0.0081980954 -0.0008808085 -0.0139251637 0.0168026724
#> 10 0.0086006183 -0.0191480851 0.0019233953 -0.0037319808 0.0008160965
#> 2019-01-16 2019-01-17 2019-01-18 2019-01-22 2019-01-23
#> 1 0.0006225251 0.012588750 0.020516528 -0.025881514 -0.0139925124
#> 2 0.0013612867 0.013697743 0.017136792 -0.021715190 -0.0064770046
#> 3 0.0022461590 0.017929158 0.017173118 -0.031168895 -0.0180964485
#> 4 0.0025809220 0.005144429 0.004208833 -0.002275472 0.0052935181
#> 5 -0.0015278336 0.004961335 0.013654370 -0.016821225 0.0037758715
#> 6 -0.0073864628 0.021016129 0.010077461 -0.014104143 -0.0096270731
#> 7 0.0002826256 0.008323762 0.014163217 -0.007444989 0.0055280671
#> 8 0.0263321323 0.006417563 0.018311941 -0.009884454 -0.0002749251
#> 9 -0.0022902675 0.008584956 0.019702313 -0.022857809 -0.0044027415
#> 10 -0.0038397004 0.014827578 0.023542428 -0.015275991 0.0010884267
#> 2019-01-24 2019-01-25 2019-01-28 2019-01-29 2019-01-30
#> 1 0.0018277208 0.020269006 -0.0149593645 0.0072686284 0.020723360
#> 2 0.0105346877 0.014733325 -0.0040431935 0.0112460435 0.014521073
#> 3 -0.0163822749 0.015961092 -0.0211747733 -0.0111654798 0.013879088
#> 4 -0.0022560009 -0.001265646 0.0037923048 0.0044858680 0.006994825
#> 5 -0.0010155000 0.009823728 -0.0026636804 0.0001654900 -0.002219753
#> 6 0.0101832630 0.031120219 -0.0014781764 -0.0189958555 0.002374046
#> 7 -0.0004141748 0.006355271 -0.0037585270 0.0026443561 0.012590902
#> 8 0.0056223661 0.010669833 -0.0010920364 -0.0070466152 -0.003415347
#> 9 0.0268202084 0.021082593 -0.0141199851 -0.0137834391 0.026150552
#> 10 -0.0030617864 0.014132427 -0.0009823253 -0.0003916924 0.004339525
#> 2019-01-31 2019-02-01 2019-02-04 2019-02-05 2019-02-06
#> 1 -0.0007308137 0.0090453019 0.0070605183 -0.001316566 -0.0078991692
#> 2 0.0031348231 0.0027702668 0.0054502459 0.005835526 -0.0015139580
#> 3 -0.0176333651 -0.0023617855 0.0061552554 0.029411765 0.0134857143
#> 4 0.0139843722 -0.0047482641 0.0050774401 0.001355200 -0.0031949644
#> 5 0.0215356972 -0.0000288866 -0.0007992307 0.004318217 -0.0037177122
#> 6 0.0064726708 -0.0014458986 0.0067284910 0.012662412 -0.0148130252
#> 7 0.0046001350 0.0057093904 0.0052757831 0.004965675 0.0008310123
#> 8 -0.0011034762 0.0038367580 0.0056659031 -0.002006878 -0.0005345201
#> 9 0.0127040999 0.0072948734 0.0066659816 0.007626970 0.0011650848
#> 10 0.0016286558 -0.0061449527 0.0076770861 0.010169734 0.0009335215
#> 2019-02-07 2019-02-08 2019-02-11 2019-02-12 2019-02-13
#> 1 -0.032660196 -0.0072849821 0.0100890716 0.0091109263 0.0197681365
#> 2 -0.012267260 -0.0004762901 0.0050359669 0.0186528870 0.0044866338
#> 3 -0.011727560 0.0244180511 0.0325239259 -0.0882416435 -0.0002365831
#> 4 0.006929315 0.0039295860 0.0013301623 -0.0003444053 0.0016601003
#> 5 -0.006398211 0.0002490855 -0.0004883910 0.0058612013 0.0031286032
#> 6 -0.023555826 0.1485982126 0.0190198510 0.0713405187 0.0095428677
#> 7 -0.004580784 0.0041323408 -0.0008505548 0.0104082313 0.0043384095
#> 8 -0.001276889 -0.0094885980 0.0049551951 0.0203091433 0.0020006500
#> 9 -0.016372707 0.0080863740 0.0011198317 0.0198327205 0.0026417110
#> 10 0.006675294 -0.0067079961 0.0064030164 0.0122311922 0.0020121244
#> 2019-02-14 2019-02-15
#> 1 0.0075799398 0.016975751
#> 2 -0.0036946113 0.010291083
#> 3 0.0087573728 -0.021820742
#> 4 -0.0024342157 0.006083278
#> 5 0.0003761233 0.015013138
#> 6 -0.0050412271 -0.063611363
#> 7 -0.0026920071 0.011096203
#> 8 -0.0115933357 0.025028326
#> 9 0.0026617120 0.007643313
#> 10 -0.0008146489 0.008606333
#>
#> Clustering vector:
#> [1] 7 2 10 9 7 5 9 7 7 9 9 5 7 2 9 4 4 4 7 5 8 4 7 7 9
#> [26] 2 9 2 7 2 9 9 9 2 8 5 8 4 9 9 9 7 7 2 1 1 2 7 2 4
#> [51] 2 4 9 4 9 2 4 8 10 2 8 7 8 10 7 8 8 1 5 8 7 8 7 7 7
#> [76] 7 2 4 8 4 5 2 7 7 2 5 4 9 2 5 5 2 8 4 7 5 7 7 4 4
#> [101] 8 5 7 10 2 4 7 4 8 5 7 1 7 6 4 10 7 9 9 2 7 5 7 7 5
#> [126] 1 1 4 2 2 8 10 7 2 7 5 5 5 5 4 10 2 4 7 4 4 5 1 2 7
#> [151] 9 7 7 4 7 4 7 2 2 1 4 4 4 4 8 2 4 4 9 4 2 7 4 2 1
#> [176] 7 9 2 1 2 4 9 7 7 8 10 7 2 2 7 2 5 5 8 4 1 9 2 7 5
#> [201] 5 4 2 2 9 9 7 9 10 7 8 2 7 1 7 8 10 7 4 2 1 1 7 7 7
#> [226] 2 7 7 1 9 2 7 4 7 5 7 4 7 7 7 9 7 9 9 7 9 9 2 5 9
#> [251] 7 2 4 9 7 2 8 2 2 2 8 7 7 7 8 10 4 8 9 5 4 9 4 1 2
#> [276] 4 10 10 2 7 10 2 2 5 7 2 7 7 7 8 4 10 9 2 7 2 10 9 4 4
#> [301] 7 2 6 7 9 5 7 5 7 8 2 2 4 2 7 2 7 5 2 1 7 1 8 7 9
#> [326] 7 8 7 9 9 2 1 2 7 4 7 9 4 7 3 5 7 1 7 2 9 8 2 9 2
#> [351] 7 7 4 1 5 7 10 1 7 8 2 4 4 7 8 4 7 2 2 2 7 4 5 8 2
#> [376] 4 2 4 5 8 4 1 10 2 1 9 2 9 2 7 4 5 8 2 10 8 10 7 2 7
#> [401] 7 10 7 7 4 7 8 2 2 8 4 1 4 2 9 4 4 7 4 8 8 9 7 2 9
#> [426] 8 7 7 7 5 5 2 2 7 10 10 10 8 7 10 9 8 7 10 4 7 9 9 9 2
#> [451] 6 6 2 4 5 10 7 8 2 2 2 8 2 9 7 10 5 1 2 4 7 7 9 4 4
#> [476] 7 5 7 9 4 4 8 2 7 7 1 5 2 7 5 2 1 4 9 1 5 2 2 7 7
#> [501] 8 7
#>
#> Within cluster sum of squares by cluster:
#> [1] 1.4608721 5.1714436 0.0000000 1.9768890 2.9347019 0.5638137 5.3152104
#> [8] 1.2836711 4.8632869 2.5438801
#> (between_SS / total_SS = 22.3 %)
#>
#> Available components:
#>
#> [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
#> [6] "betweenss" "size" "iter" "ifault"
Next, we’ll combine the clusters from the k_means_obj with the umap_results_tbl.
Begin with the k_means_obj
Augment the k_means_obj with the stock_date_matrix_tbl to get the clusters added to the end of the tibble
Select just the symbol and .cluster columns
Left join the result with the umap_results_tbl by the symbol column
Left join the result with the result of sp_500_index_tbl %>% select(symbol, company, sector) by the symbol column.
Store the output as umap_kmeans_results_tbl
# Use your dplyr & broom skills to combine the k_means_obj with the umap_results_tbl
# Convert it to a tibble with broom
kmeans_10_clusters_tbl <- kmeans_10_obj %>%
augment (stock_date_matrix_tbl) %>%
# Select the data we need
select (symbol, .cluster)
# Bind data together
umap_kmeans_results_tbl <- umap_results_tbl %>%
left_join (kmeans_10_clusters_tbl, by = "symbol" ) %>%
left_join (sp_500_index_tbl %>% select (symbol, company, sector), by = "symbol" )
umap_kmeans_results_tbl
# Output: umap_kmeans_results_tbl
Plot the K-Means and UMAP results.
Begin with the umap_kmeans_results_tbl
Use ggplot() mapping V1, V2 and color = .cluster
Add the geom_point() geometry with alpha = 0.5
Apply colors as you desire (e.g. scale_color_manual(values = palette_light() %>% rep(3)))
# Visualize the combined K-Means and UMAP results
umap_kmeans_results_tbl %>%
mutate (label_text = str_glue ("Customer: {symbol}
Cluster: {.cluster}" )) %>%
ggplot (aes (V1, V2, color = .cluster)) +
# Geometries
geom_point (alpha = 0.5 ) +
# Formatting
# scale_color_manual(values=c("#2d72d6", "#2dc6d6", "#2dd692")) +
scale_color_manual (values = palette_light () %>% rep (3 )) +
labs (title = "Visualize the combined K-Means and UMAP results" ,
subtitle = "" ,
caption = "" ) +
theme (legend.position = "none" )
Congratulations! You are done with the 1st challenge!